home *** CD-ROM | disk | FTP | other *** search
/ CGI How-To / CGI HOW-TO.iso / chap4 / 4_6 / dyn_pl / dynhtm.pl < prev    next >
Encoding:
Perl Script  |  1996-06-15  |  1001 b   |  73 lines

  1. #!/usr/bin/perl
  2.  
  3. # Include the cgi library from chapter 1.
  4.  
  5. require "cgilib.pl";
  6.  
  7. # Initialize some variables
  8.  
  9. $data = "";
  10. %cgiDict;
  11. $theUrl = "";
  12. $title = "";
  13.  
  14. #Print the content type
  15.  
  16. print "Content-type: text/html\n\n";
  17.  
  18. #Read the cgi input
  19.  
  20. &readData(*data);
  21. &parseData(*data,*cgiDict);
  22.  
  23. # Figure out which button was selected
  24.  
  25. if($cgiDict{"choice"} eq "library")
  26. {
  27.     $title = "CGI input library";
  28.     open(in,"cgilib.pl");
  29. }
  30. else
  31. {
  32.     $title = "dynhtm.pl script";
  33.     open(in,"dynhtm.pl");
  34. }
  35.  
  36. # output the HTML header
  37. print "<HTML>\n";
  38. print "<HEAD>\n";
  39.  
  40.  
  41. print "<TITLE>",$title,"</TITLE>\n";
  42.  
  43.  
  44. print "</HEAD>\n";
  45. print "<BODY>\n";
  46. print "<PRE>\n";
  47.  
  48. while(<in>)
  49. {
  50.     # Since this is file is treated as html,
  51.     # get rid of restricted
  52.     # characters. Do & first to avoid
  53.     # recoding of <, ...
  54.     
  55.     s/&/&/g;
  56.     s/</</g;
  57.     s/>/>/g;
  58.     s/\"/"/g;
  59.     
  60.     print $_;
  61. }
  62.  
  63.  
  64. close(in);
  65.  
  66. # Output the html footer
  67. print "</PRE>\n";
  68. print "</BODY>\n";
  69. print "</HTML>\n";
  70.  
  71. 1;
  72.  
  73.